package com.qifenqian.turbot.module.model

import android.content.Context
import com.qifenqian.turbot.base.BaseModel
import com.qifenqian.turbot.module.contract.StatisticsContract
import com.qifenqian.turbot.module.entity.response.statistic.SoldDishEntity
import com.qifenqian.turbot.module.entity.response.statistic.StatisticsEntity
import com.qifenqian.turbot.net.ModelCallback
import com.qifenqian.turbot.net.NetObserver

/**
 * @author H
 * @createTime 2018/12/27 17:00
 * @description
 * @see
 * @since
 */
class StatisticsModel(context: Context) : BaseModel(context), StatisticsContract.Model {

    override fun getDishStatistics(date: String, type: Int, callback: ModelCallback<List<SoldDishEntity>>) {
        mClient!!.getDishStatistics(date, type)
                .subscribe(object : NetObserver<List<SoldDishEntity>>(mContext, false) {
                    override fun onSuccess(msg: String?, t: List<SoldDishEntity>?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }

    override fun getBusinessStatistics(date: String, type: Int, callback: ModelCallback<StatisticsEntity>) {
        mClient!!.getBusinessStatistics(date, type)
                .subscribe(object : NetObserver<StatisticsEntity>(mContext, false) {
                    override fun onSuccess(msg: String?, t: StatisticsEntity?) {
                        callback.onSuccess(msg, t)
                    }

                    override fun onFailure(code: Int, msg: String?) {
                        callback.onFailure(code, msg)
                    }
                })
    }
}
